
// await 同步 变成异步不阻塞后面的代码
function promise1() {
    console.log('promise 1')
    return new Promise(function (resove) {
      setTimeout(function () {
        console.log('promise resolve 1')
        resove()
        // throw new Error('promise1 error')
    }, 5000)
    })
  }
  
  function promise2() {
    console.log('promise 2')
    return new Promise(function (resove) {
      console.log('promise resolve 2')
      resove()
    })
  }
  
  // eg1
  async function init() {
    var result1 =  promise1();
    var result2 =  promise2()

    console.log('promise over')
    setTimeout(function () {
      console.log(123)
    }, 5000)
  
  
  }

  async function init2() {
    var result1 =  promise1();
    var result2 =  promise2()

    await result1;
    await result2;
  
    console.log('promise over')
    setTimeout(function () {
      console.log(123)
    }, 5000)
  
  
  }
  
  init()
  
//   promise 1
//   promise 2
//   promise resolve 2
//   promise over
//   promise resolve 1
//   123


// promise 1
// promise 2
// promise resolve 2
// promise resolve 1
// promise over
// 123

  